<template>
  <div class="app-container">
    <el-form ref="form" :model="form" style="width:500px;" label-width="120px">
      <el-form-item label="新密码">
        <el-input v-model="form.newPsd" />
      </el-form-item>
      <el-form-item label="重复新密码">
        <el-input v-model="form.onceNewPsd" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { ChangePsd } from '@/api/user'
export default {
  data() {
    return {
      form: {
        newPsd: '',
        onceNewPsd: ''
      }
    }
  },
  methods: {
    onSubmit() {
      if (this.form.newPsd !== this.form.onceNewPsd) {
        this.$message({
          message: '两次输入密码不一致',
          type: 'error'
        })
        return
      }
      if (this.form.newPsd.length < 5) {
        this.$message({
          message: '密码长度大于5',
          type: 'error'
        })
        return
      }
      ChangePsd({ newPsd: this.form.newPsd }).then(response => {
        this.$message({
          message: '密码修改成功',
          type: 'success'
        })
        this.$router.push('/')
      })
    },
    onCancel() {
      this.$message({
        message: 'cancel!',
        type: 'warning'
      })
    }
  }
}
</script>

<style scoped>
.line{
  text-align: center;
}
</style>

